<?PHP
	/************************************************************************
	*       This file, in addition to all other parts of X7 Chat are        *
	*                   Copyright 2003-2007 by Tim Chamness.                *
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	* Version:          X7 Chat 3.0.0-A2                                    *
	* Release Date:     October 20, 2007                                    *
	* Author:           Tim Chamness                                        *
	* Copyright:        2003-2007 by Tim Chamness                           *
	* Website:          http://www.x7chat.com/                              *
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	* X7 Chat 3 is free software; you can redistribute it and/or modify     *
	* it under the terms of the GNU General Public License as published by  *
	* the Free Software Foundation; either version 3 of the License, or     *
	* (at your option) any later version.                                   *
	*                                                                       *
	* X7 Chat 3 is distributed in the hope that it will be useful, but      *
	* WITHOUT ANY WARRANTY; without even the implied warranty of            *
	* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
	* General Public License for more details.                              *
	*                                                                       *
	* You should have received a copy of the GNU General Public License     *
	* along with this program.  If not, see <http://www.gnu.org/licenses/>. *
	*                                                                       *
	* Additional Terms, compatible with Section 7 of the GNU GPL v3,        *
	* apply to X7 Chat 3 and all X7 Chat 3 files, including this one.       *
	* You should have received a copy of these Additional Terms in the      *
	* file docs/COPYING.ADDITIONAL_TERMS.  If you did not receive a copy    *
	* please visit <http://www.x7chat.com/COPYING.ADDITIONAL_TERMS/>.       *
	************************************************************************/

	$GLOBALS['OUTPUT']->master_section = 'appearance';
	$GLOBALS['OUTPUT']->minor_section = $GLOBALS['LANG']->lang_admin->managethemes;
	$GLOBALS['OUTPUT']->cpmenu = $menus[$GLOBALS['OUTPUT']->master_section];
	
	// Obtain a list of themes
	$dir = dir("./themes");
	$themes = array();
	while($file = $dir->read()){
		if($file[0] == '.' || !is_file("./themes/{$file}/meta.php")) continue;
		
		include("./themes/{$file}/meta.php");
		if(!$theme_info['admin_hide']){
			$themes[$file] = $theme_info;
			$themes[$file]['hide'] = !in_array($file,$settings['available_themes']);
		}
	}
	
	$makedefault = x7in::read('makedefault');
	if(!empty($makedefault)){
		$makedefault = base64_decode($makedefault);
		
		if(isset($themes[$makedefault])){
			$settings['default_theme'] = $makedefault;
			$settings['key'] = 'settings';
			$GLOBALS['DATABASE']->put('system',$settings);
		}
	}
	
	$hide = x7in::read('hide');
	if(!empty($hide)){
		$hide = base64_decode($hide);
		
		if(isset($themes[$hide]) && in_array($hide,$settings['available_themes'])){
			unset($settings['available_themes'][array_search($hide,$settings['available_themes'])]);
			$themes[$hide]['hide'] = true;
			$settings['key'] = 'settings';
			$GLOBALS['DATABASE']->put('system',$settings);
		}
	}
	
	$unhide = x7in::read('unhide');
	if(!empty($unhide)){
		$unhide = base64_decode($unhide);
		
		if(isset($themes[$unhide]) && !in_array($unhide,$settings['available_themes'])){
			$settings['available_themes'][] = $unhide;
			$themes[$unhide]['hide'] = false;
			$settings['key'] = 'settings';
			$GLOBALS['DATABASE']->put('system',$settings);
		}
	}
	
	$GLOBALS['OUTPUT']->themes = $themes;
	
	echo tpl_appearance::appearance();
?>